/*
Date:20210427 17:08pm
key:递归好像也可以，不过比较慢
 */
class Solution {
public:
void pre(TreeNode*root,vector<TreeNode*>&v)
{
    if(root!=nullptr)
    {
        v.push_back(root);
        pre(root->left,v);
        pre(root->right,v);

    }
}
    void flatten(TreeNode* root) 
    {
        vector<TreeNode*>v;
        pre(root,v);
        for(int i=1;i<v.size();i++)
        {
            //cout<<v[i]->val<<" ";
            v[i-1]->left=nullptr;
            v[i-1]->right=v[i];
        }
    }
};